<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <script th:src="@{/erp/assets/js/jquery.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <title>货位编辑</title>
</head>
<body>

<form>
    <div class="edit_menber" id="edit_menber_style">
        <input th:value="${param.warehouseId}" id="iid" type="hidden">
        <input th:value="${param.areaId}" id="iid2" type="hidden">
        <input th:value="${param.shelfId}" id="iid3" type="hidden">
        <input th:value="${param.id}" name="id" type="hidden">
        <ul class=" page-content">
            <div class="Operate_cont clearfix">
                <div class="brand_detailed">
                    <ul class="Info_style clearfix" style="width:510px; margin-top:0px;">
                        <li>
                            <label class="label_name">货位编号：</label>
                            <span class="name">
                                <input name="cargoSpaceNo" required th:value="${param.cargoSpaceNo}" type="text" class="text_add"
                                       style="width:140px;">
                            </span>
                        </li>
                        <li>
                            <label class="label_name">货架编号：</label>
                            <span class="name">
                                 <select  name="shelfId" required id="shelfNo" style="margin-left:10px;">
                                    <option value="" selected disabled>--请选择货架--</option>
                                </select>
                            </span>
                        </li>
                        <li>
                            <label class="label_name">所属仓库：</label>
                            <span class="name">
                                 <!--下拉框-->
                                <select name="warehouseId" required onchange="getAreaByWid()" id="warehouseName"
                                        style="margin-left:10px;">
                                    <option value="" selected disabled>--请选择仓库--</option>
                                </select>
                            </span>
                        </li>
                        <li>
                            <label class="label_name">所属货区：</label>
                            <span class="name">
                                 <select  name="areaId" required id="areaName" onchange="getShelfByAid()"
                                         style="margin-left:10px;">
                                    <option value="" selected disabled>--请选择货区--</option>
                                </select>
                            </span>
                        </li>
                        <li>
                            <label class="label_name">货区编号：</label>
                            <span class="name">
                                 <input name="" required th:value="${param.areaNo}" type="text" class="text_add"
                                        style="width:140px;">
                            </span>
                        </li>
                        <!--  <li>
                              <label class="label_name">负责人：</label>
                              <span class="name">
                                  <input name="" type="text" class="text_add" style="width:140px;" value="张三"></span></li>
                          <li>
                              <label class="label_name">联系电话：</label>
                              <span class="name">
                                  <input name="" type="text" class="text_add" style="width:140px;"
                                         value="15234682542"></span></li>
                          <li>
                              <label class="label_name">主要商品：</label>
                              <span class="name">
                                  <input name="" type="text" class="text_add" style="width:140px;" value="旭派电池">
                              </span>
                          </li>-->
                        <!-- <li>
                             <label class="label_name">创建时间：</label>
                             <span class="name">2017-3-1</span>
                         </li>-->
                        <li>
                            <label class="label_name">状态：</label>
                            <span class="name">
                                <span th:if="${param.cargoSpaceStatus[0]} eq '1' ">
                                    <input type="radio" checked   th:value="1" placeholder="" class="text_add"
                                           name="cargoSpaceStatus"/>有货&nbsp;&nbsp;
                                     <input type="radio"    th:value="2" placeholder="" class="text_add"
                                            name="cargoSpaceStatus"/>无货
                                </span>
                                <span th:if="${param.cargoSpaceStatus[0]} eq '2' ">
                                    <input type="radio"   th:value="1" placeholder="" class="text_add"
                                           name="cargoSpaceStatus"/>有货&nbsp;&nbsp;
                                     <input type="radio" checked   th:value="2" placeholder="" class="text_add"
                                            name="cargoSpaceStatus"/>无货
                                </span>
                            </span>
                        </li>
                        <li class="b_Introduce">
                            <label class="label_name">描述：</label><br/>
                            <span class="name">
                                <textarea cols="40" required rows="8" th:value="${param.cargoSpaceRemark}">旭派电池专用</textarea>
                            </span>
                        </li>
                    </ul>
                    <li>
                        <div class="" style=" text-align:center">
                            <input class="btn btn-primary" id="tijiao" type="submit" value="提交">
                            <input class="btn btn-primary" id="tijiao1" type="reset" value="取消">
                        </div>

                    </li>

                </div>
            </div>
        </ul>
    </div>


</form>

<script>

    jQuery(function ($) {
        var iid = $("#iid").val();
        var iid2 = $("#iid2").val();
        var iid3 = $("#iid3").val();
        $.ajax({
            url: '/warehouse/list',
            type: 'post',
            success: function (res) {
                for (var i = 0; i < res.length; i++) {
                    if (iid == res[i].id) {
                        $("#warehouseName").append('<option selected value="' + res[i].id + '">' + res[i].warehouseName + '</option>')
                    } else {
                        $("#warehouseName").append('<option  value="' + res[i].id + '">' + res[i].warehouseName + '</option>')
                    }
                }
            }
        })


        $.post("/area/listByWid",{warehouseId:iid}, function (res) {
            for (var i = 0; i < res.length; i++) {
                if (iid2 == res[i].id) {
                    $("#areaName").append('<option selected value="' + res[i].id + '">' + res[i].areaName + '</option>')
                } else {
                    $("#areaName").append('<option  value="' + res[i].id + '">' + res[i].areaName + '</option>')
                }
            }
        });

        $.post("/shelf/listByAid",{areaId: iid2}, function (res) {
            for (var i = 0; i < res.length; i++) {
                if (iid3 == res[i].id) {
                    $("#shelfNo").append('<option selected value="' + res[i].id + '">' + res[i].shelfNo + '</option>')
                } else {
                    $("#shelfNo").append('<option  value="' + res[i].id + '">' + res[i].shelfNo + '</option>')
                }
            }
        })

        $('form').submit(function () {
            var data = $('form').serialize();
            $.ajax({
                url: '/cargoSpace/update',
                type: 'post',
                data: data,
                success: function (res) {
                    if (res.rs) {
                        parent.layer.msg(res.msg, {icon: 1});
                        $('#btn',parent.window.document).click();
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
            return false;
        });

        $('#tijiao1').on('click', function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    });

    //仓库联动库区
    function getAreaByWid() {
        var wId = $("#warehouseName").find("option:selected").val();
        $("#areaName").empty();
        $.post("/area/listByWid", {warehouseId: wId}, function (res) {
            $("#areaName").append('<option value="" selected disabled>--请选择货区--</option>');
            for (var i = 0; i < res.length; i++) {
                $("#areaName").append('<option value="' + res[i].id + '">' + res[i].areaName + '</option>')
            }
        });
        return false;
    }

    //货区联动货架
    function getShelfByAid() {
        var aid = $("#areaName").find("option:selected").val();
        $("#shelfNo").empty();
        $.post("/shelf/listByAid", {areaId: aid}, function (res) {
            $("#shelfNo").append('<option value="" selected disabled>--请选择货架--</option>');
            for (var i = 0; i < res.length; i++) {
                $("#shelfNo").append('<option value="' + res[i].id + '">' + res[i].shelfNo + '</option>')
            }
        });
        return false;
    }
</script>


</body>
</html>